package com.nanyang.tms.controller.forecast;

import com.nanyang.common.core.annotation.BindParam;
import com.nanyang.common.core.annotation.SystemLog;
import com.nanyang.common.core.dict.CommonEnum;
import com.nanyang.common.core.domain.ApiResult;
import com.nanyang.common.core.exception.ServiceException;
import com.nanyang.common.core.page.PageBean;
import com.nanyang.tms.api.dto.request.forecast.ForecastFrontDetailRequest;
import com.nanyang.tms.api.dto.request.forecast.ForecastFrontPageQueryRequest;
import com.nanyang.tms.api.dto.request.forecast.ForecastPageQueryRequest;
import com.nanyang.tms.api.dto.request.forecast.ForecastUpdateStateRequest;
import com.nanyang.tms.api.dto.response.forecast.ForecastBaseResponse;
import com.nanyang.tms.api.dto.response.forecast.ForecastFrontPageResponse;
import com.nanyang.tms.api.dto.response.forecast.ForecastPageResponse;
import com.nanyang.tms.api.service.forecast.ForecastQueryRpcService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/forecastQuery")
public class ForecastQueryController {
	 @Reference(version = "1.0.0", timeout = 60000, check = false)
	 private ForecastQueryRpcService forecastQueryRpcService;

	/**
	 * 后台查询表
	 * @param param
	 * @return
	 */
	@RequestMapping(value = "/list", method = RequestMethod.POST)
	public ApiResult<PageBean<ForecastPageResponse>> listForecast(@RequestBody ForecastPageQueryRequest param) {
		ApiResult<PageBean<ForecastPageResponse>> apiResult = forecastQueryRpcService.listForecast(param);
		if (apiResult.getCode() == CommonEnum.SYSTEM_EXCEPTION.getCode()) {
			throw new ServiceException(CommonEnum.SYSTEM_EXCEPTION.getCode(), apiResult.getMessage());
		}
		return apiResult;
	}
	/**
	 * 后台查询根据编码
	 * @param forecastCode
	 * @return
	 */
	@RequestMapping(value = "/selectByCode/{forecastCode}", method = RequestMethod.GET)
	public ApiResult<ForecastBaseResponse> selectByCode(@PathVariable("forecastCode") String forecastCode) {
		ApiResult<ForecastBaseResponse> apiResult = forecastQueryRpcService.selectByCode(forecastCode);
		if (apiResult.getCode() == CommonEnum.SYSTEM_EXCEPTION.getCode()) {
			throw new ServiceException(CommonEnum.SYSTEM_EXCEPTION.getCode(), apiResult.getMessage());
		}
		return apiResult;
	}


	/**
	 * 前台-查询表
	 * @param param
	 * @return
	 */
	@BindParam
	@RequestMapping(value = "/listForecast", method = RequestMethod.POST)
	public ApiResult<PageBean<ForecastFrontPageResponse>> listFrontForecast(@BindParam @RequestBody ForecastFrontPageQueryRequest param) {
		ApiResult<PageBean<ForecastFrontPageResponse>> apiResult = forecastQueryRpcService.listFrontForecast(param);
		if (apiResult.getCode() == CommonEnum.SYSTEM_EXCEPTION.getCode()) {
			throw new ServiceException(CommonEnum.SYSTEM_EXCEPTION.getCode(), apiResult.getMessage());
		}
		return apiResult;
	}
	/**
	 * 前台-查询根据编码
	 * @param param
	 * @return
	 */
	@BindParam
	@RequestMapping(value = "/detail", method = RequestMethod.POST)
	public ApiResult<ForecastBaseResponse> selectByCompanyCode(@BindParam @RequestBody ForecastFrontDetailRequest param) {
		ApiResult<ForecastBaseResponse> apiResult = forecastQueryRpcService.selectByCompanyCode(param);
		if (apiResult.getCode() == CommonEnum.SYSTEM_EXCEPTION.getCode()) {
			throw new ServiceException(CommonEnum.SYSTEM_EXCEPTION.getCode(), apiResult.getMessage());
		}
		return apiResult;
	}
	/**
	 * 前台-取消
	 * @param param
	 * @return
	 */
	@BindParam
	@RequestMapping(value = "/cancelState", method = RequestMethod.POST)
	public ApiResult<Boolean> cancelState(@BindParam @RequestBody ForecastUpdateStateRequest param) {
		ApiResult<Boolean> apiResult = forecastQueryRpcService.cancelState(param);
		if (apiResult.getCode() == CommonEnum.SYSTEM_EXCEPTION.getCode()) {
			throw new ServiceException(CommonEnum.SYSTEM_EXCEPTION.getCode(), apiResult.getMessage());
		}
		return apiResult;
	}
	/**
	 * 前台-查询打印标签
	 * @param param
	 * @return
	 */
	@BindParam
	@RequestMapping(value = "/printTag", method = RequestMethod.POST)
	public ApiResult<String> printTag(@BindParam @RequestBody ForecastFrontDetailRequest param) {
		ApiResult<String> apiResult = forecastQueryRpcService.printTag(param);
		if (apiResult.getCode() == CommonEnum.SYSTEM_EXCEPTION.getCode()) {
			throw new ServiceException(CommonEnum.SYSTEM_EXCEPTION.getCode(), apiResult.getMessage());
		}
		return apiResult;
	}

	/**
	 * 前台-查询打印交货清单
	 * @param param
	 * @return
	 */
	@BindParam
	@RequestMapping(value = "/printList", method = RequestMethod.POST)
	public ApiResult<String> printList(@BindParam @RequestBody ForecastFrontDetailRequest param) {
		ApiResult<String> apiResult = forecastQueryRpcService.printList(param);
		if (apiResult.getCode() == CommonEnum.SYSTEM_EXCEPTION.getCode()) {
			throw new ServiceException(CommonEnum.SYSTEM_EXCEPTION.getCode(), apiResult.getMessage());
		}
		return apiResult;
	}
}
